package com.jeethink.erp.warehouse.controller;

import java.util.List;

import com.jeethink.common.core.domain.entity.TbShop;
import com.jeethink.common.core.domain.entity.TbWarehouse;
import com.jeethink.erp.commodity.domain.TbCommodity;
import com.jeethink.erp.pile.domain.TbStockPile;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.jeethink.common.annotation.Log;
import com.jeethink.common.core.controller.BaseController;
import com.jeethink.common.core.domain.AjaxResult;
import com.jeethink.common.enums.BusinessType;
import com.jeethink.erp.warehouse.service.ITbWarehouseService;
import com.jeethink.common.utils.poi.ExcelUtil;
import com.jeethink.common.core.page.TableDataInfo;

/**
 * 仓库Controller
 * 
 * @author ypr
 * @date 2021-05-26
 */
@RestController
@RequestMapping("/erp/warehouse")
public class TbWarehouseController extends BaseController
{
    @Autowired
    private ITbWarehouseService tbWarehouseService;

    /**
     * 查询仓库列表
     */
    @PreAuthorize("@ss.hasPermi('erp:warehouse:list')")
    @GetMapping("/list")
    public AjaxResult list(TbWarehouse tbWarehouse)
    {
        List<TbWarehouse> list = tbWarehouseService.selectTbWarehouseList(tbWarehouse);
        return AjaxResult.success(list);
    }

    /**
     * 导出仓库列表
     */
    @PreAuthorize("@ss.hasPermi('erp:warehouse:export')")
    @Log(title = "仓库", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TbWarehouse tbWarehouse)
    {
        List<TbWarehouse> list = tbWarehouseService.selectTbWarehouseList(tbWarehouse);
        ExcelUtil<TbWarehouse> util = new ExcelUtil<TbWarehouse>(TbWarehouse.class);
        return util.exportExcel(list, "warehouse");
    }

    /**
     * 获取仓库详细信息
     */
    @PreAuthorize("@ss.hasPermi('erp:warehouse:query')")
    @GetMapping(value = "/{warehouseId}")
    public AjaxResult getInfo(@PathVariable("warehouseId") Long warehouseId)
    {
        return AjaxResult.success(tbWarehouseService.selectTbWarehouseById(warehouseId));
    }

    /**
     * 新增仓库
     */
    @PreAuthorize("@ss.hasPermi('erp:warehouse:add')")
    @Log(title = "仓库", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbWarehouse tbWarehouse)
    {
        return toAjax(tbWarehouseService.insertTbWarehouse(tbWarehouse));
    }

    /**
     * 修改仓库
     */
    @PreAuthorize("@ss.hasPermi('erp:warehouse:edit')")
    @Log(title = "仓库", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbWarehouse tbWarehouse)
    {
        return toAjax(tbWarehouseService.updateTbWarehouse(tbWarehouse));
    }

    /**
     * 删除仓库
     */
    @PreAuthorize("@ss.hasPermi('erp:warehouse:remove')")
    @Log(title = "仓库", businessType = BusinessType.DELETE)
	@DeleteMapping("/{warehouseIds}")
    public AjaxResult remove(@PathVariable Long[] warehouseIds)
    {
        return toAjax(tbWarehouseService.deleteTbWarehouseByIds(warehouseIds));
    }

    /**
     * 获取仓库下拉树列表
     */
    @GetMapping("/treeselect")
    public AjaxResult treeselect(TbWarehouse tbWarehouse)
    {
        List<TbWarehouse> list = tbWarehouseService.selectTbWarehouseList(tbWarehouse);
        return AjaxResult.success(tbWarehouseService.buildWareHouseTreeSelect(list));
    }

    @GetMapping("/warehouseList")
    public AjaxResult warehouseList(){
        List<TbWarehouse> warehouseList = tbWarehouseService.selectTbWarehouseList(new TbWarehouse());
        return AjaxResult.success(warehouseList);
    }
}
